package com.nbjtjc.safe.mapper.sys;

import com.nbjtjc.safe.model.sys.SysNoticeTarget;
import com.nbjtjc.util.MyMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysNoticeTargetMapper extends MyMapper<SysNoticeTarget> {

    @Select("select target_user_id from sys_notice_target where sys_notice_id=#{sysNoticeId}")
    List<Integer> findUserIdsByNoticeId(@Param("sysNoticeId") int sysNoticeId);

    @Select("select sys_notice_id from sys_notice_target where target_user_id=#{userId}" +
            " and has_read=#{hasRead}")
    List<Integer> findNoticeIdsByUserId(@Param("userId") int userId
            ,@Param("hasRead") boolean hasRead);
    @Select("select count(*) from sys_notice_target where target_user_id=#{userId}" +
            " and has_read=#{hasRead}")
    Integer findCountByUserId(@Param("userId") int userId
            ,@Param("hasRead") boolean hasRead);
    @Select("select * from sys_notice_target where target_user_id=#{userId}" +
            " and has_read=#{hasRead} order by create_time desc")
    List<SysNoticeTarget> findNoticeTargetByUserId(@Param("userId") int userId
            ,@Param("hasRead") boolean hasRead);

    @Select("select * from sys_notice_target where target_user_id=#{userId}" +
            " order by has_read asc")
    List<SysNoticeTarget> findNoticeByUserId(@Param("userId") int userId);
}